import { defineStore } from "pinia";
import { useStorage } from "@vueuse/core";
import defaultSettings from "@/settings";
import { pinia } from "@/store/storeIndex";

// 导入 Element Plus 中英文语言包
import zhCn from "element-plus/es/locale/lang/zh-cn";
import en from "element-plus/es/locale/lang/en";
import { computed } from "vue";


export const useAppStore = defineStore("app", () => {
    const languageRef = useStorage("language", defaultSettings.language);


    const localeComputed = computed(() => {
        if (languageRef?.value == "en") {
          return en;
        } else {
          return zhCn;
        }
      });

        /**
   * 切换语言
   *
   * @param val
   */
  function changeLanguage(val: string) {
    languageRef.value = val;
  }

  return {
    languageRef,
    localeComputed,
    changeLanguage,
   
  };
});

export function useAppStoreHook() {
  return useAppStore(pinia);
}